package com.yh.correct.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.IFileAttachmentsMapper;
import com.yh.correct.model.FileAttachments;
import com.yh.correct.model.Page;
import com.yh.correct.service.IFileAttachmentsService;

/**
 * 檔案附件服務接口
 * 
 * @author 王卫
 *
 */
@Service
public class FileAttachmentsServiceImpl implements IFileAttachmentsService {

	private static Logger logger = LogManager.getLogger(FileAttachmentsServiceImpl.class);

	@Autowired
	private IFileAttachmentsMapper fileAttachmentsMapper;
	/**
	 * 查询档案附件
	 */
	@Override
	public List<FileAttachments> getFileAttachments(int fileattachments) throws Exception {
		// TODO Auto-generated method stub
		return fileAttachmentsMapper.getFileAttachments(fileattachments);
	}
	/**
	 * 添加档案附件
	 */
	@Override
	public int addFileAttachments(FileAttachments fileattachments) throws Exception {
		// TODO Auto-generated method stub
		return fileAttachmentsMapper.addFileAttachments(fileattachments);
	}
	/**
	 * 删除档案附件
	 */
	@Override
	public int delFileAttachments(int fileattachments) throws Exception {
		// TODO Auto-generated method stub
		return fileAttachmentsMapper.delFileAttachments(fileattachments);
	}
	/**
	 * 修改档案附件
	 */
	@Override
	public int editFileAttachments(FileAttachments fileattachments) throws Exception {
		// TODO Auto-generated method stub
		return fileAttachmentsMapper.editFileAttachments(fileattachments);
	}

	@Override
	public Page queryLikeFileAttachments(Map<String, Object> cond) throws Exception {
		// TODO Auto-generated method stub
		Page page = new Page();
		// 根据条件查询符合的用户列表记录总数，赋值给page的totalNum变量
		page.setTotalNum(fileAttachmentsMapper.getLikeFileAttachmentsCount(cond));
		// 从请求参数中获取每页大小
		int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
		page.setPageSize(pageSize);
		// 从请求参数中获取当前页码
		int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
		page.setCurPageNum(curPageNum);
		// 动态计算总页数(总记录数 除以 每页大小，加上 总页数 求余 每页大小，如果余数不为0，则 加 1，否则 加 0 )
		page.setTotalPage(page.getTotalNum() / pageSize + (page.getTotalNum() % pageSize == 0 ? 0 : 1));
		// 根据条件查询符合的用户列表记录，赋值给page的result变量
		page.setResult(fileAttachmentsMapper.getLikeFileAttachments(cond));

		return page;
	}

}
